# f = open(r'username.txt')
# f = open(r'D:\python_pro\python_230901\day07_文件操作\username.txt', mode='r', encoding='utf-8')
# data_discuz = f.read()
# print(data_discuz)
# f.close()
#
# # 案例2：：读文件（重点一下
# with open(r'username.txt') as f:
#     data_discuz = f.read()
#     print(data_discuz)
#
# # 案例3：写文件
# with open(r'test.txt', mode='w') as f:
#     str = 'hello world'
#     f.write(str)
#
# # 案例4：复制一张图片
# with open(r'caomei.png', mode='rb') as f1, open(r'caomei2.png', mode='wb') as f2:
#     data_discuz = f1.read()
#     f2.write(data_discuz)
# f=open(r'hello.txt',mode='r')
# with open(r'hello.txt',mode='r') as f:
#     data_discuz=f.read()
#     print(data_discuz)
#     #写文件
# with open(r'hello.txt',mode='w') as f2:
#     str="hello world"
#     f2.write(str)
#
# #图片
# with open(r'blue.jpg',mode='rb') as f1,open(r'blue2.jpg',mode='wb') as f2:
#     data_discuz=f1.read()
#     f2.write(data_discuz)
# with open(r'blue2.jpg','rb') as f:
#     data_discuz=f.read()
#     # print(data_discuz)
#
import csv
# 读取csv文件  未忽略首行
# with open(r'user.csv') as f:
#     f_csv_reader = csv.reader(f)
#     for data_discuz in f_csv_reader:
#         print(data_discuz)
#

'''看个案例：enumerate() 忽略首行

list1 = list(range(1, 11, 2))
a = enumerate(list1)
print(a)
b = list(a)
print(b)'''
#忽略首行
# with open(r'user.csv') as f:
#     f_csv_reader = csv.reader(f)
#     for i, data_discuz in enumerate(f_csv_reader):
#         if i == 0:
#             continue
#         else:
#             print(data_discuz)





'''
综合案例：
定义函数  get_csv_data()、get_data_from_csv()
定义类    Csv_Util()
参数：
返回值：列表嵌套列表，不要首行
[['test01', '123456'], ['test02', '123456'], ['test03', '123456']]
'''
def get_csv_data(path):
    user_list = []
    with open(path,mode='r',encoding='utf-8') as f:

        f_csv_reader = csv.reader(f)
        next(f_csv_reader)
        print(f_csv_reader)
        for data in f_csv_reader:
            user_list.append(data)
        print(user_list)
    return user_list
    #

    # with open(r'user.csv', mode='w', newline='') as f:
    #     f_csv_writer = csv.writer(f)
    #     f_csv_writer.writerows(user_list)
    #     print(user_list)

if __name__ == '__main__':
    path= r'user.csv'
    get_csv_data(path)

